package com.jia.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jia.dto.admin.CoordinateDto;
import com.jia.service.CoordinateService;
import com.jia.vo.Result;
import com.jia.vo.ResultCodeEnum;
import com.jia.vo.admin.CoordinateVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@Schema(description = "电池管理")
public class BatteryController {

    @Autowired
    private CoordinateService coordinateService;

    @GetMapping("/{page}/{limit}")
    public Result<Page<CoordinateVo>> coordinateList(
            @PathVariable("page") int page, @PathVariable("limit") int limit, CoordinateDto coordinateDto) {
        return Result.build(this.coordinateService.COORDINATE_VO_PAGE(page,limit,coordinateDto), ResultCodeEnum.SUCCESS);
    }

    /**
     * 获取省份
     * @return
     */
    @GetMapping("/province")
    public Result<List<String>> getprovince(){
        return Result.build(this.coordinateService.provinceList(),ResultCodeEnum.SUCCESS);
    }

    /**
     * 获取城市
     * @param province
     * @return
     */

    @GetMapping("/city/{province}")
    public Result<List<String>> getcity(@PathVariable("province") String province){
        return Result.build(this.coordinateService.cityList(province),ResultCodeEnum.SUCCESS);
    }

    /**
     * 区
     * @param city
     * @return
     */
    @GetMapping("/area/{city}")
    public Result<List<String>> getarea(@PathVariable("city") String city){
        return Result.build(this.coordinateService.areaList(city),ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改状态
     * @param id
     * @return
     */
    @GetMapping("/updateBatteryState/{id}")
    @Operation(summary = "修改用户状态")
    public Result updateState(@PathVariable("id") int id) {
        coordinateService.updateState(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    /**
     * 删除电柜
     * @param id
     * @return
     */
    @GetMapping("/deleteBattery/{id}")
    @Operation(summary = "删除电柜")
    public Result deleteBattery(@PathVariable("id") int id) {
        coordinateService.deleteBattery(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加站点
     * @param coordinateDto
     * @return
     */
    @PostMapping("addBattery")
    @Operation(summary = "添加电柜")
    public Result addBattrey(@RequestBody CoordinateDto coordinateDto) {
        this.coordinateService.addBattrey(coordinateDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
